<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="/favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/css/animate.min.css" rel="stylesheet">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet">
	<!-- 搜索样式CSS-Start -->
	<link href="/common/css/searchStyle.css" rel="stylesheet">
	<!-- 搜索样式CSS-End -->
	<!-- 下拉 -->
	<link href="/css/plugins/chosen/chosen.css" rel="stylesheet">
	<!-- jqgrid-->
    <link href="/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                             <form id="seachform">
	                             <div class="seach-context">
											 <label>项目名称 :</label><input id="name" placeholder="请输入系统名称"/>
											 <label>项目状态:</label>
											 <select class="chosen-select" tabindex="8" id="status">
											 </select>
					             </div>
					            <button id="resetBtn" type="reset" class="btn btn-w-m btn-white">重置</button>
								<button id="addBtn" type="button"  power="ADDWARNINGCONFIG" class="btn btn-w-m btn-success">新增预警配置信息</button>
								<button id="searchBtn" type="button" class="btn btn-w-m btn-white">查询</button>
							</form>
                        </div>
                        <div class="jqGrid_wrapper">
	                                <table id="warningConfigTable"></table>
	                                <div id="warningConfigTable_2"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
	<!-- End Panel Other -->
	<script src="/js/jquery.min.js?v=2.1.4"></script>
	<script src="/js/bootstrap.min.js?v=3.3.5"></script>
	<script src="/js/content.min.js?v=1.0.0"></script>
	<script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
	<script src="/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="/common/petecat.js"></script>
	<script src="/common/bootstrap-table.js"></script>
	<script src="/common/bootstrap-table-treetable.js"></script>
	<script src="/common/form.js"></script>
	<!-- HTML之间的传值 -->
	<script src="/js/jquery.params.js"></script>
	<script src="/js/plugins/layer-pc/layer.js"></script>
	<script src="/js/jquery.cookie.js"></script>
    <!-- 组件通用 -->
    <script src="/common/frame.js"></script>
    <!-- 下拉 -->
	<script src="/js/plugins/chosen/chosen.jquery.js"></script>
	<!-- jqgridS -->
   	<script src="/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="/js/plugins/jqgrid/i18n/grid.locale-cn.js"></script>
    <script src="/js/plugins/jqgrid/jquery.jqGrid.min.js"></script>
    <!-- jqgridE -->
<script type="text/javascript">
checkPowerAndJump("QRYWARNINGCONFIG")
    $(function(){
    	var status =JSON.parse('[{"key":"","value":"全部"},{"key":"0","value":"禁用"},{"key":"1","value":"启用"}]');
    	var item = {
    		id:"status",
    		data:status
    	};
    	initSelectData(item);
    	$('#resetBtn').click(function(){
    		$('#seachform').resetForm();
    	});
        $('#addBtn').click(function(){
            winLayerIndex = layer.open({
                type: 2,
                title: '新增预警配置信息',
                shade: 0.8,
                area: ['380px', '80%'],
                content: ['/base/warning/rule/index.html', 'auto'], //iframe的url，no代表不显示滚动条
                end: function(){ //此处用于演示
                	$("#warningConfigTable").jqGrid('setGridParam',{    
                        datatype:'json',    
                        postData:{'status':$("#status").val(),"name":$("#name").val()},  
                        page:1    
                    }).trigger("reloadGrid");
                }
            });
            layer.full(winLayerIndex);
        });

        $('#searchBtn').click(function(){
            $("#warningConfigTable").jqGrid('setGridParam',{    
                datatype:'json',    
                postData:{'status':$("#status").val(),"name":$("#name").val()},  
                page:1    
            }).trigger("reloadGrid");  
        });
        var header = 'Bearer '+getSessionData('userToken');
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#warningConfigTable").jqGrid({
    		url: BASE_URL+'/base/project/queryProjectByTree',
            datatype: "json",
            height: 600,
            autowidth: true,
            shrinkToFit: true,
            rowNum: 20,
            rowList: [10, 20, 30],
            jsonReader:{
            	root:'data.result',
            	page: "1",//数据页码
            	total: "3",//数据总页码
            	records: "totalSize",//数据总记录数
            	repeatitems: true,//如果设为false，则jqGrid在解析json时，会根据name(colmodel 指定的name)来搜索对应的数据元素（即可以json中元素可以不按顺序）
            	cell: "cell",//root 中row 行
            	id: "projectId",//唯一标识
            	
            },loadBeforeSend: function(jqXHR){
                jqXHR.setRequestHeader("Authorization",header);
            },
            colNames: ["项目名称", "创建时间", "项目状态"],
            colModel: [
            {
                name: "projectName"
            },
            {
                name: "projectCreateTime",
        		formatter:function(index,rowId,row){
        			return timeTransfoDate(row['projectCreateTime']);
        		}
            },
            {
                name: "projectStatus",
        		formatter:function(index,rowId,row){
        			return row['projectStatus'] == 0?"禁用":"启用";
        		}
            }],
            pager: "#warningConfigTable_2",
            caption: "项目规则管理",
            hidegrid: false,
            subGrid:true,
            subGridRowExpanded : function(subgrid_id, row_id) {
            	var subgrid_table_id, pager_id;
                subgrid_table_id = subgrid_id + "_t";
                pager_id = "p_" + subgrid_table_id;
                $("#" + subgrid_id).html(
                        "<table id='" + subgrid_table_id
                            + "' class='scroll'></table><div id='"
                            + pager_id + "' class='scroll'></div>");
            	$("#"+ subgrid_table_id).jqGrid({
            		url: BASE_URL+'/base/warningconfig/queryWarningConfigTree?projectId='+row_id,
                    datatype: "json",
                    autowidth: true,
                    height: 400,
                    shrinkToFit: true,
                    rowNum: 20,
                    rowList: [10, 20, 30],
                    jsonReader:{
                    	root:'data.result',
                    	page: "1",//数据页码
                    	total: "3",//数据总页码
                    	records: "totalSize",//数据总记录数
                    	repeatitems: true,//如果设为false，则jqGrid在解析json时，会根据name(colmodel 指定的name)来搜索对应的数据元素（即可以json中元素可以不按顺序）
                    	cell: "cell",//root 中row 行
                    	id: "configId",//唯一标识
                    },loadBeforeSend: function(jqXHR){
                        jqXHR.setRequestHeader("Authorization",header);
                    },
                    colNames: ["规则组名称", "创建时间", "规则组状态","操作"],
                    colModel: [
                    {
                        name: "configName"
                    },
                    {
                        name: "configCreateTime",
                		formatter:function(index,rowId,row){
                			return timeTransfoDate(row['createTime']);
                		}
                    },
                    {
                        name: "configStatus",
                		formatter:function(index,rowId,row){
                			return row['status'] == 0?"禁用中":"启用中";
                		}
                    },
                    {
                        name: "opt",
                        width:80,
                		formatter:function(index,rowId,row){
                			var html = "";
                			if(row['status'] == 0){
                				html = '<a class="open" style="color:red;" uid="'+row['configId']+'" href="javascript:void(0)" title="启用">启用</a>&nbsp;&nbsp;&nbsp;';             				
                			}
                			return html+'<a class="upd" uid="'+row['configId']+'" href="javascript:void(0)" title="修改">修改</a>&nbsp;&nbsp;&nbsp;<a class="del" uid="'+row['configId']+'" href="javascript:void(0)" title="删除">删除</a>';
                		}
                    }],
                    gridComplete: function(){
                    	$('.upd').bind('click',function(){
                    		updateConfig = layer.open({
                     			title:'修改预警配置',
                     			type:2,
                     			content:'/base/warning/rule/index_update.html?configId='+$(this).attr('uid'),
                     			shade:0.8,
                     			end:function(){
                     				$("#warningConfigTable").jqGrid('setGridParam',{    
                                        datatype:'json',    
                                        postData:{'status':$("#status").val(),"name":$("#name").val()},  
                                        page:1    
                                    }).trigger("reloadGrid");
                     			}
                     		});
                     	 layer.full(updateConfig);  
                    	});
                    	$(".open").on('click',function(){
                    		var id = $(this).attr('uid');
                    		layer.confirm("是否启用此配置信息?",{icon:3,title:'一个项目只能启用一个配置信息'},function(){
                    			var req = {};
                        		req['reqJSON'] ={
                        				type:'put',
                        				url:BASE_URL+'/base/warningconfig/updateStatusConfigById?configId='+id+'&projectId='+row_id
                        		};
                        		req['useToken'] = true;
                        		req['successFn'] = function(respData){
                                     layer.msg(respData.message, {icon: 6,time:2000},function(){
                                         if(respData.code == SUCCESS_CODE){
                                             window.location.reload();
                                         }
                                     });
                                };
                        		ajaxRequest(req);
                    		});
                    	});
                    	
                    	$(".del").bind('click',function(){
                    		var id = $(this).attr('uid');
                    		layer.confirm("是否删除此配置信息?",{icon:3,title:'温馨提示'},function(){
                    			var req = {};
                        		req['reqJSON'] ={
                        				type:'delete',
                        				url:BASE_URL+'/base/warningconfig/removeWarningConfigByConfigId?configId='+id
                        		};
                        		req['useToken'] = true;
                        		req['successFn'] = function(respData){
                                     layer.msg(respData.message, {icon: 6,time:2000},function(){
                                         if(respData.code == SUCCESS_CODE){
                                             window.location.reload();
                                         }
                                     });
                                };
                        		ajaxRequest(req);
                    		});
                    	});
                    },
                    subGrid:true,
                    subGridRowExpanded : function(subgrid_id1, row_id1) {
                    	var subgrid_table_id, pager_id;
                        subgrid_table_id = subgrid_id1 + "_t";
                        pager_id = "p_" + subgrid_table_id;
                        $("#" + subgrid_id1).html(
                                "<table id='" + subgrid_table_id
                                    + "' class='scroll'></table><div id='"
                                    + pager_id + "' class='scroll'></div>");
                    	$("#"+ subgrid_table_id).jqGrid({
                    		url: BASE_URL+'/base/warningrule/queryWarningRuleTree?ewaringId='+row_id1,
                            datatype: "json",
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 20,
                            height: 400,
                            rowList: [10, 20, 30],
                            jsonReader:{
                            	root:'data.result',
                            	page: "1",//数据页码
                            	total: "3",//数据总页码
                            	records: "totalSize",//数据总记录数
                            	repeatitems: true,//如果设为false，则jqGrid在解析json时，会根据name(colmodel 指定的name)来搜索对应的数据元素（即可以json中元素可以不按顺序）
                            	cell: "cell",//root 中row 行
                            	id: "ruleId",//唯一标识
                            },loadBeforeSend: function(jqXHR){
                                jqXHR.setRequestHeader("Authorization",header);
                            },
                            colNames: ["预警类型", "键", "值","范围值","预警时间间隔","预警次数","预警开始时间","预警结束时间","创建时间","规则标题","规则备注","状态"],
                            colModel: [
                            {
                                name: "ruleType",
                        		formatter:function(index,rowId,row){
                        			ruleType = row['ruleType'];
                        			if(ruleType=="0"){
                        				text = "服务器信息";
                        			}else if(ruleType=="1"){
                        				text = "硬件";
                        			}else if(ruleType=="2"){
                        				text = "软件";
                        			}else if(ruleType=="3"){
                        				text = "应用";
                        			}else if(ruleType=="4"){
                        				text = "服务器状态";
                        			}else if(ruleType=="5"){
                        				text = "其他";
                        			}else if(ruleType=="6"){
                        				text = "串口";
                        			}
                        			return text;
                        	    }
                            },
                            {
                                name: "ruleKeys"
                            },
                            {
                                name: "ruleValue"
                            },
                            {
                                name: "ruleValueRange",
                        		formatter:function(index,rowId,row){
                        			ruleType = row['ruleValueRange'];
                        			if(ruleType=="0"){
                        				text = "相等";
                        			}else if(ruleType=="1"){
                        				text = "大于";
                        			}else if(ruleType=="-1"){
                        				text = "小于";
                        			}
                        			return text;
                        	    }
                            },
                            {
                                name: "ruleRangeMinute"
                            },
                            {
                                name: "ruleRangeCount"
                            },
                            {
                                name: "ruleRangeStartTime"
                            },
                            {
                                name: "ruleRangeEndTime"
                            },
                            {
                                name: "ruleCreateTime",
                        		formatter:function(index,rowId,row){
                        			return timeTransfoDate(row['ruleCreateTime']);
                        	    }
                            },
                            {
                                name: "title"
                            },
                            {
                                name: "remark"
                            },
                            {
                                name: "ruleStatus",
                        		formatter:function(index,rowId,row){
                        			return row['ruleStatus'] == 0?"禁用":"启用";
                        	    }
                            }],
                            subGrid:true,
                            subGridRowExpanded : function(subgrid_id2, row_id2) {
                            	var subgrid_table_id, pager_id;
                                subgrid_table_id = subgrid_id2 + "_t";
                                pager_id = "p_" + subgrid_table_id;
                                $("#" + subgrid_id2).html(
                                        "<table id='" + subgrid_table_id
                                            + "' class='scroll'></table><div id='"
                                            + pager_id + "' class='scroll'></div>");
                            	$("#"+ subgrid_table_id).jqGrid({
                            		url: BASE_URL+'/base/warningempl/queryWarningEmplTree?ruleId='+row_id2,
                                    datatype: "json",
                                    autowidth: true,
                                    shrinkToFit: true,
                                    height: 400,
                                    rowNum: 20,
                                    rowList: [10, 20, 30],
                                    jsonReader:{
                                    	root:'data.result',
                                    	page: "1",//数据页码
                                    	total: "3",//数据总页码
                                    	records: "totalSize",//数据总记录数
                                    	repeatitems: true,//如果设为false，则jqGrid在解析json时，会根据name(colmodel 指定的name)来搜索对应的数据元素（即可以json中元素可以不按顺序）
                                    	cell: "cell",//root 中row 行
                                    	id: "id",//唯一标识
                                    },loadBeforeSend: function(jqXHR){
                                        jqXHR.setRequestHeader("Authorization",header);
                                    },
                                    colNames: ["预警人员名称", "SMS权限", "EMAIL权限"],
                                    colModel: [
                                    {
                                        name: "userName"
                                    },
                                    {
                                        name: "emplSms",
                                        formatter:function(index,rowId,row){
                                        	return icon_state(row['emplSms']);
                                        }
                                    },
                                    {
                                        name: "emplEmail",
                                        formatter:function(index,rowId,row){
                                        	return icon_state(row['emplEmail']);
                                        }
                                    }]
                            	});
                            	
                            }
                   	 });
                    	
                   }
            	});
            }
        });
        
    });
function icon_state(state){
	var pic_html = state == 0 ?"<div style='width:25px;height:25px;background:url("+"/common/images/icon_no.png"+") no-repeat 0 0;background-size:cover;'></div>":"<div style='width:25px;height:25px;background:url("+"/common/images/icon_yes.png"+") no-repeat 0 0;background-size:cover;'></div>";
	return pic_html;
}
</script>
</body>
</html>